package edu.sfsu.powerrangers.jeopardy.editor;

import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

public class OpenMenuItem extends JMenuItem {
	private static final long serialVersionUID = 1L;
	
	public OpenMenuItem() {
		super("Open...");
		setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
		addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FileDialog fd = new FileDialog(new Frame(), "Open File", FileDialog.LOAD);
				fd.setVisible(true);
				if (fd.getFile() != null) {
					File f = new File(fd.getDirectory()+System.getProperty("file.separator")+fd.getFile());
					new EditorFrame(f).setVisible(true);
				}
			}
		});
	}
}
